package Demo1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

class Student implements Comparable<Student>{
    String name;
    int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(Student o) {
        return Integer.compare(this.age,o.age);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class demo4 {
    public static void main(String[] args) {
//        ArrayList<String> arrayList = new ArrayList<>();
//        arrayList.add("hello");
//        arrayList.add("the");
//        arrayList.add("world");
//
//        Collections.sort(arrayList, (s1, s2) -> s2.compareTo(s1));
//
//        System.out.println(arrayList);

        List<Student> people = new ArrayList<>();
        people.add(new Student("Alice", 25));
        people.add(new Student("Bob", 22));
        people.add(new Student("Charlie", 30));

        Collections.sort(people);

        System.out.println(people);
    }
}
